package com.example.processor;

import com.example.initialize.Animal;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

    // 初始化之前调用
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean.getClass().isAssignableFrom(Animal.class)) {
            System.out.println("MyBeanPostProcessor...postProcessBeforeInitialization..." + beanName);
        }
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    // 初始化之后调用--
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean.getClass().isAssignableFrom(Animal.class)) {
            System.out.println("MyBeanPostProcessor...postProcessAfterInitialization..." + beanName);
        }
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }

    /*
            实现类名                                    作用
            AutowiredAnnotationBeanPostProcessor        用来完成依赖注入
            AbstractAutoProxyCreator                    用来完成代理对象的创建
            AbstractAdvisingBeanPostProcessor           将Aop中的通知作用于特点的B ean上
     */
}
